<script setup lang="ts">
import { ref } from 'vue'
import radioCell from '@/components/radio-cell.vue'

const emit = defineEmits(['close'])
const show = ref(false)
defineExpose({
  show,
})

const editRef = ref()
const formModel = ref({
  placeName: '',
  logo: '',
  is_kefu: '123453654321',
  kefu_tel: '',
  kefu_wx: '',
  qrcode: '',
})
const qrcodeFileList = ref([])
const logoFileList = ref([])
function handleSubmit() {
  editRef.value.validate().then(({ valid, errors }) => {
    if (valid) {
      console.log('表单验证通过')
      // 提交表单逻辑
      emit('close', false)
      show.value = false
    }
    else {
      console.log('表单验证不通过')
    }
  })
}
function handleClose() {
//   show.value = false

}
const fileList = ref([])
function customUpload(file, formData, options: any) {
  const uploadTask = uni.uploadFile({
    url: 'actionUrl', // 仅为示例，非真实的接口地址
    header: options.header,
    name: options.name,
    fileName: options.name,
    fileType: options.fileType,
    formData,
    filePath: file.url,
    success(res) {
      if (res.statusCode === options.statusCode) {
        // 设置上传成功
        options.onSuccess(res, file, formData)
      }
      else {
        // 设置上传失败
        options.onError({ ...res, errMsg: res.errMsg || '' }, file, formData)
      }
    },
    fail(err) {
      // 设置上传失败
      options.onError(err, file, formData)
    },
  })
  // 设置当前文件加载的百分比
  uploadTask.onProgressUpdate((res) => {
    options.onProgress(res, file)
  })
}
</script>

<template>
  <wd-popup v-model="show" lock-scroll position="bottom" :safe-area-inset-bottom="true" closable custom-style="height: auto;padding-bottom: 40rpx;overflow: hidden;border-radius: 32rpx 32rpx 0 0;" @close="handleClose">
    <view class="wot-form-title">
      【 商户 ＞ 品牌信息 】
    </view>
    <scroll-view scroll-y>
      <wd-form ref="editRef" :model="formModel">
        <wd-cell-group border>
          <wd-input
            v-model="formModel.placeName"
            label="场地名称："
            placeholder="场地名称"
            label-width="100px"
            prop="name"
            clearable
          />
          <view class="wot-tips">
            请修改成自己的场地名称
          </view>
          <wd-cell title="品牌LOGO：" title-width="100px">
            <view class="inp-num">
              <wd-upload v-model:file-list="logoFileList" :limit="1" :upload-method="customUpload" />
            </view>
          </wd-cell>
          <radio-cell
            label-width="100px"
            title="客服开关："
          >
            <wd-radio-group
              v-model="formModel.is_kefu" shape="dot" inline
            >
              <wd-radio value="1">
                开启
              </wd-radio>
              <wd-radio value="2">
                关闭
              </wd-radio>
            </wd-radio-group>
          </radio-cell>
          <wd-input
            v-model="formModel.kefu_tel"
            label="客服手机："
            placeholder="客服手机"
            label-width="100px"
            prop="kefu_tel"
            clearable
          />
          <wd-cell title="客服二维码：" title-width="100px">
            <view class="inp-num">
              <wd-upload v-model:file-list="qrcodeFileList" :limit="1" :upload-method="customUpload" />
            </view>
          </wd-cell>
        </wd-cell-group>

        <view class="btn-outer-pd">
          <wd-button type="primary" size="small" block @click="handleSubmit">
            保存修改
          </wd-button>
        </view>
      </wd-form>
    </scroll-view>
  </wd-popup>
</template>

<style lang="scss" scoped>
.desc{
    padding: 40rpx 20rpx;
    line-height: 40rpx;
    font-size: 24rpx;
    color: #ED6A0C;
}
</style>
